home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / os2 / adaptor.zip / ADAPT.ZIP / adaptor / src / transfor.c < prev    next >
Text File  |  1994-01-03  |  13KB  |  619 lines

  1. # include "Transfor.h"
  2. # include "yyTransf.w"
  3. # include <stdio.h>
  4. # if defined __STDC__ | defined __cplusplus
  5. #  include <stdlib.h>
  6. # else
  7.    extern void exit ();
  8. # endif
  9. # include "Tree.h"
  10. # include "Definiti.h"
  11.  
  12. # ifndef NULL
  13. # define NULL 0L
  14. # endif
  15. # ifndef false
  16. # define false 0
  17. # endif
  18. # ifndef true
  19. # define true 1
  20. # endif
  21.  
  22. # ifdef yyInline
  23. # define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) \
  24.   if ((ptr = (tree) free) >= (tree) max) ptr = alloc (); \
  25.   free += nodesize [kind]; \
  26.   ptr->yyHead.yyMark = 0; \
  27.   ptr->Kind = kind;
  28. # else
  29. # define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) ptr = make (kind);
  30. # endif
  31.  
  32. # define yyWrite(s) (void) fputs (s, yyf)
  33. # define yyWriteNl (void) fputc ('\n', yyf)
  34.  
  35. # line 25 "Transform.puma"
  36.  
  37. # include <stdio.h>
  38. # include "Tree.h"
  39. # include "Idents.h"
  40. # include "StringMe.h"
  41.  
  42.  
  43.  
  44. static FILE * yyf = stdout;
  45.  
  46. static void yyAbort
  47. # ifdef __cplusplus
  48.  (char * yyFunction)
  49. # else
  50.  (yyFunction) char * yyFunction;
  51. # endif
  52. {
  53.  (void) fprintf (stderr, "Error: module Transform, routine %s failed\n", yyFunction);
  54.  exit (1);
  55. }
  56.  
  57. tTree CombineACF ARGS((tTree list1, tTree list2));
  58. tTree CombineBTP ARGS((tTree list1, tTree list2));
  59. tTree ReplaceACF ARGS((tTree old, tTree newelem, tTree newnext));
  60. static tTree ReplaceACF_h ARGS((tTree old, tTree newelem, tTree newnext));
  61. static void ReplaceACF_Set ARGS((tTree newelem, int line));
  62. tTree ReplaceDECL ARGS((tTree old, tTree newelem, tTree newnext));
  63. static tTree ReplaceDECL_h ARGS((tTree old, tTree newelem, tTree newnext));
  64. tTree AppendDECLS ARGS((tTree t, tTree newlist));
  65. tTree MakeFuncCall ARGS((tIdent id, tTree exps));
  66. static void MakeFuncParams ARGS((tTree t));
  67. tTree ExpToVarParam ARGS((tTree exp));
  68. tTree AppendParam ARGS((tTree plist, tTree param));
  69.  
  70. tTree CombineACF
  71. # if defined __STDC__ | defined __cplusplus
  72. (register tTree list1, register tTree list2)
  73. # else
  74. (list1, list2)
  75.  register tTree list1;
  76.  register tTree list2;
  77. # endif
  78. {
  79. # line 44 "Transform.puma"
  80.   {
  81. # line 45 "Transform.puma"
  82.    if (! ((list1 == NoTree))) goto yyL1;
  83.   }
  84.    return list2;
  85. yyL1:;
  86.  
  87.   if (list1->Kind == kACF_EMPTY) {
  88. # line 49 "Transform.puma"
  89.    return list2;
  90.  
  91.   }
  92.   if (list1->Kind == kACF_LIST) {
  93. # line 53 "Transform.puma"
  94.   {
  95. # line 54 "Transform.puma"
  96.    if (! ((list1->ACF_LIST.Next == NoTree))) goto yyL3;
  97.   {
  98. # line 55 "Transform.puma"
  99.  list1->ACF_LIST.Next = list2;
  100.   }
  101.   }
  102.    return list1;
  103. yyL3:;
  104.  
  105.   if (list1->ACF_LIST.Next->Kind == kACF_EMPTY) {
  106. # line 59 "Transform.puma"
  107.   {
  108. # line 60 "Transform.puma"
  109.  list1->ACF_LIST.Next = list2;
  110.   }
  111.    return list1;
  112.  
  113.   }
  114. # line 64 "Transform.puma"
  115.   {
  116. # line 65 "Transform.puma"
  117.  list1->ACF_LIST.Next = CombineACF (list1->ACF_LIST.Next, list2);
  118.   }
  119.    return list1;
  120.  
  121.   }
  122. # line 69 "Transform.puma"
  123.    return mACF_LIST (list1, list2);
  124.  
  125. }
  126.  
  127. tTree CombineBTP
  128. # if defined __STDC__ | defined __cplusplus
  129. (register tTree list1, register tTree list2)
  130. # else
  131. (list1, list2)
  132.  register tTree list1;
  133.  register tTree list2;
  134. # endif
  135. {
  136. # line 84 "Transform.puma"
  137.   {
  138. # line 85 "Transform.puma"
  139.    if (! ((list1 == NoTree))) goto yyL1;
  140.   }
  141.    return list2;
  142. yyL1:;
  143.  
  144.   if (list1->Kind == kBTP_EMPTY) {
  145. # line 89 "Transform.puma"
  146.    return list2;
  147.  
  148.   }
  149.   if (list1->Kind == kBTP_LIST) {
  150. # line 93 "Transform.puma"
  151.   {
  152. # line 94 "Transform.puma"
  153.    if (! ((list1->BTP_LIST.Next == NoTree))) goto yyL3;
  154.   {
  155. # line 95 "Transform.puma"
  156.  list1->BTP_LIST.Next = list2;
  157.   }
  158.   }
  159.    return list1;
  160. yyL3:;
  161.  
  162.   if (list1->BTP_LIST.Next->Kind == kBTP_EMPTY) {
  163. # line 99 "Transform.puma"
  164.   {
  165. # line 100 "Transform.puma"
  166.  list1->BTP_LIST.Next = list2;
  167.   }
  168.    return list1;
  169.  
  170.   }
  171. # line 104 "Transform.puma"
  172.   {
  173. # line 105 "Transform.puma"
  174.  list1->BTP_LIST.Next = CombineBTP (list1->BTP_LIST.Next, list2);
  175.   }
  176.    return list1;
  177.  
  178.   }
  179. # line 109 "Transform.puma"
  180.    return mBTP_LIST (list1, list2);
  181.  
  182. }
  183.  
  184. tTree ReplaceACF
  185. # if defined __STDC__ | defined __cplusplus
  186. (register tTree old, register tTree newelem, register tTree newnext)
  187. # else
  188. (old, newelem, newnext)
  189.  register tTree old;
  190.  register tTree newelem;
  191.  register tTree newnext;
  192. # endif
  193. {
  194. # line 128 "Transform.puma"
  195.  
  196. tTree t;
  197.  
  198.   if (old->Kind == kACF_LIST) {
  199.   if (equalint (old->ACF_LIST.Elem->ACF_NODE.Label, 0)) {
  200. # line 132 "Transform.puma"
  201.   {
  202. # line 134 "Transform.puma"
  203.  if (newelem == NoTree)
  204.          t = old->ACF_LIST.Next;
  205.        else
  206.          t = ReplaceACF_h (old, newelem, newnext);
  207.  
  208.   }
  209.    return t;
  210.  
  211.   }
  212. # line 142 "Transform.puma"
  213.   {
  214. # line 143 "Transform.puma"
  215.  
  216.       if (newelem == NoTree)
  217.         { t = mACF_DUMMY ();
  218.           t->ACF_NODE.Label = old->ACF_LIST.Elem->ACF_NODE.Label;
  219.           t->ACF_NODE.Line = old->ACF_LIST.Elem->ACF_NODE.Line;
  220.           old->ACF_LIST.Elem = t;
  221.           old->ACF_LIST.Next = newnext;
  222.           t = old;
  223.         }
  224.        else
  225.          t = ReplaceACF_h (old, newelem, newnext);
  226.  
  227.   }
  228.    return t;
  229.  
  230.   }
  231.  yyAbort ("ReplaceACF");
  232. }
  233.  
  234. static tTree ReplaceACF_h
  235. # if defined __STDC__ | defined __cplusplus
  236. (register tTree old, register tTree newelem, register tTree newnext)
  237. # else
  238. (old, newelem, newnext)
  239.  register tTree old;
  240.  register tTree newelem;
  241.  register tTree newnext;
  242. # endif
  243. {
  244. # line 162 "Transform.puma"
  245.  
  246. tTree hacf;
  247. int hlabel;
  248.  
  249.   if (old->Kind == kACF_LIST) {
  250. # line 167 "Transform.puma"
  251.   {
  252. # line 168 "Transform.puma"
  253.    if (! (old->ACF_LIST.Elem == newelem)) goto yyL1;
  254.   {
  255. # line 169 "Transform.puma"
  256.  old->ACF_LIST.Next = newnext;
  257.   }
  258.   }
  259.    return old;
  260. yyL1:;
  261.  
  262.   if (Tree_IsType (newelem, kACF_NODE)) {
  263. # line 173 "Transform.puma"
  264.   {
  265. # line 175 "Transform.puma"
  266.  
  267.        newelem->ACF_NODE.Label = old->ACF_LIST.Elem->ACF_NODE.Label;
  268.        old->ACF_LIST.Elem->ACF_NODE.Label = 0;
  269.        newelem->ACF_NODE.Line  = old->ACF_LIST.Elem->ACF_NODE.Line;
  270.        old->ACF_LIST.Elem = newelem;
  271.        old->ACF_LIST.Next = newnext;
  272.  
  273.   }
  274.    return old;
  275.  
  276.   }
  277.   if (newelem->Kind == kACF_LIST) {
  278. # line 185 "Transform.puma"
  279.   {
  280. # line 187 "Transform.puma"
  281.  hlabel = old->ACF_LIST.Elem->ACF_NODE.Label;
  282.        ReplaceACF_Set (newelem, old->ACF_LIST.Elem->ACF_NODE.Line);
  283.        newelem->ACF_LIST.Elem->ACF_NODE.Label = hlabel;
  284.        hacf = newelem;
  285.        while (hacf->ACF_LIST.Next != NoTree)
  286.            hacf = hacf->ACF_LIST.Next;
  287.        hacf->ACF_LIST.Next = newnext;
  288.  
  289.   }
  290.    return newelem;
  291.  
  292.   }
  293.   }
  294.  yyAbort ("ReplaceACF_h");
  295. }
  296.  
  297. static void ReplaceACF_Set
  298. # if defined __STDC__ | defined __cplusplus
  299. (register tTree newelem, register int line)
  300. # else
  301. (newelem, line)
  302.  register tTree newelem;
  303.  register int line;
  304. # endif
  305. {
  306.   if (newelem == NoTree) return;
  307.   if (newelem->Kind == kACF_LIST) {
  308. # line 200 "Transform.puma"
  309.   {
  310. # line 201 "Transform.puma"
  311.  newelem->ACF_LIST.Elem->ACF_NODE.Label = 0;
  312.       newelem->ACF_LIST.Elem->ACF_NODE.Line = line;
  313.       if (newelem->ACF_LIST.Next != NoTree)
  314.          ReplaceACF_Set (newelem->ACF_LIST.Next, line);
  315.  
  316.   }
  317.    return;
  318.  
  319.   }
  320. ;
  321. }
  322.  
  323. tTree ReplaceDECL
  324. # if defined __STDC__ | defined __cplusplus
  325. (register tTree old, register tTree newelem, register tTree newnext)
  326. # else
  327. (old, newelem, newnext)
  328.  register tTree old;
  329.  register tTree newelem;
  330.  register tTree newnext;
  331. # endif
  332. {
  333. # line 220 "Transform.puma"
  334.  
  335. tTree t;
  336.  
  337.   if (old->Kind == kDECL_LIST) {
  338. # line 224 "Transform.puma"
  339.   {
  340. # line 225 "Transform.puma"
  341.  if (newelem == NoTree)
  342.          t = old->DECL_LIST.Next;
  343.        else
  344.          t = ReplaceDECL_h (old, newelem, newnext);
  345.  
  346.   }
  347.    return t;
  348.  
  349.   }
  350.  yyAbort ("ReplaceDECL");
  351. }
  352.  
  353. static tTree ReplaceDECL_h
  354. # if defined __STDC__ | defined __cplusplus
  355. (register tTree old, register tTree newelem, register tTree newnext)
  356. # else
  357. (old, newelem, newnext)
  358.  register tTree old;
  359.  register tTree newelem;
  360.  register tTree newnext;
  361. # endif
  362. {
  363. # line 237 "Transform.puma"
  364.  
  365. tTree hdecl;
  366.  
  367.   if (old->Kind == kDECL_LIST) {
  368.   if (Tree_IsType (newelem, kDECL_NODE)) {
  369. # line 241 "Transform.puma"
  370.   {
  371. # line 244 "Transform.puma"
  372.  old->DECL_LIST.Elem = newelem;
  373.        old->DECL_LIST.Next = newnext;
  374.  
  375.   }
  376.    return old;
  377.  
  378.   }
  379.   if (newelem->Kind == kDECL_LIST) {
  380. # line 250 "Transform.puma"
  381.   {
  382. # line 252 "Transform.puma"
  383.  hdecl = newelem;
  384.        while (hdecl->DECL_LIST.Next != NoTree)
  385.            hdecl = hdecl->DECL_LIST.Next;
  386.        hdecl->DECL_LIST.Next = newnext;
  387.  
  388.   }
  389.    return newelem;
  390.  
  391.   }
  392.   }
  393. # line 260 "Transform.puma"
  394.   {
  395. # line 261 "Transform.puma"
  396.    printf ("ReplaceDECL_h failed, old tree = \n");
  397. # line 262 "Transform.puma"
  398.    WriteTree (stdout, old);
  399. # line 263 "Transform.puma"
  400.    printf ("new elem = \n");
  401. # line 264 "Transform.puma"
  402.    WriteTree (stdout, newelem);
  403. # line 265 "Transform.puma"
  404.    FileUnparse (stdout, newelem);
  405. # line 266 "Transform.puma"
  406.    printf ("new tail = \n");
  407. # line 267 "Transform.puma"
  408.    WriteTree (stdout, newnext);
  409. # line 268 "Transform.puma"
  410.    kill_in_protocol ();
  411.   }
  412.    return NoTree;
  413.  
  414. }
  415.  
  416. tTree AppendDECLS
  417. # if defined __STDC__ | defined __cplusplus
  418. (register tTree t, register tTree newlist)
  419. # else
  420. (t, newlist)
  421.  register tTree t;
  422.  register tTree newlist;
  423. # endif
  424. {
  425. # line 280 "Transform.puma"
  426.   {
  427. # line 281 "Transform.puma"
  428.    if (! (newlist == NoTree)) goto yyL1;
  429.   {
  430. # line 282 "Transform.puma"
  431.    printf ("AppendDECLS: newlist = NoTree\n");
  432. # line 283 "Transform.puma"
  433.    exit (- 1);
  434.   }
  435.   }
  436.    return t;
  437. yyL1:;
  438.  
  439.   if (t->Kind == kDECL_LIST) {
  440.   if (t->DECL_LIST.Elem->Kind == kSTMT_FUNC_DECL) {
  441.   if (newlist->Kind == kDECL_LIST) {
  442.   if (newlist->DECL_LIST.Elem->Kind == kSTMT_FUNC_DECL) {
  443. # line 287 "Transform.puma"
  444.   {
  445. # line 288 "Transform.puma"
  446.  t->DECL_LIST.Next = AppendDECLS (t->DECL_LIST.Next, newlist);
  447.   }
  448.    return t;
  449.  
  450.   }
  451.   }
  452. # line 292 "Transform.puma"
  453.    return AppendDECLS (newlist, t);
  454.  
  455.   }
  456. # line 296 "Transform.puma"
  457.   {
  458. # line 297 "Transform.puma"
  459.  t->DECL_LIST.Next = AppendDECLS (t->DECL_LIST.Next, newlist);
  460.   }
  461.    return t;
  462.  
  463.   }
  464.   if (t->Kind == kDECL_EMPTY) {
  465. # line 301 "Transform.puma"
  466.    return newlist;
  467.  
  468.   }
  469.  yyAbort ("AppendDECLS");
  470. }
  471.  
  472. tTree MakeFuncCall
  473. # if defined __STDC__ | defined __cplusplus
  474. (register tIdent id, register tTree exps)
  475. # else
  476. (id, exps)
  477.  register tIdent id;
  478.  register tTree exps;
  479. # endif
  480. {
  481. # line 315 "Transform.puma"
  482.  
  483. tTree v;
  484.  
  485. # line 319 "Transform.puma"
  486.   {
  487. # line 320 "Transform.puma"
  488.  MakeFuncParams (exps);
  489.       v = mFUNC_CALL_EXP (mPROC_OBJ (id), exps);
  490.   }
  491.    return v;
  492.  
  493. }
  494.  
  495. static void MakeFuncParams
  496. # if defined __STDC__ | defined __cplusplus
  497. (register tTree t)
  498. # else
  499. (t)
  500.  register tTree t;
  501. # endif
  502. {
  503.   if (t == NoTree) return;
  504.   if (t->Kind == kBTE_LIST) {
  505.   if (t->BTE_LIST.Elem->Kind == kVAR_EXP) {
  506. # line 327 "Transform.puma"
  507.   {
  508. # line 328 "Transform.puma"
  509.    MakeFuncParams (t->BTE_LIST.Next);
  510. # line 329 "Transform.puma"
  511.  t->Kind = kBTP_LIST;
  512.        t->BTP_LIST.Elem = mVAR_PARAM (t->BTE_LIST.Elem->VAR_EXP.V);
  513.   }
  514.    return;
  515.  
  516.   }
  517.   if (t->BTE_LIST.Elem->Kind == kNAMED_EXP) {
  518.   if (t->BTE_LIST.Elem->NAMED_EXP.VAL->Kind == kVAR_EXP) {
  519. # line 333 "Transform.puma"
  520.   {
  521. # line 334 "Transform.puma"
  522.    MakeFuncParams (t->BTE_LIST.Next);
  523. # line 335 "Transform.puma"
  524.  t->Kind = kBTP_LIST;
  525.        t->BTE_LIST.Elem->Kind = kNAMED_PARAM;
  526.        t->BTE_LIST.Elem->NAMED_PARAM.VAL = mVAR_PARAM (t->BTE_LIST.Elem->NAMED_EXP.VAL->VAR_EXP.V);
  527.   }
  528.    return;
  529.  
  530.   }
  531. # line 340 "Transform.puma"
  532.   {
  533. # line 341 "Transform.puma"
  534.    MakeFuncParams (t->BTE_LIST.Next);
  535. # line 342 "Transform.puma"
  536.  t->Kind = kBTP_LIST;
  537.        t->BTE_LIST.Elem->Kind = kNAMED_PARAM;
  538.        t->BTE_LIST.Elem->NAMED_PARAM.VAL = mVAR_PARAM (mADDR(t->BTE_LIST.Elem->NAMED_EXP.VAL));
  539.   }
  540.    return;
  541.  
  542.   }
  543. # line 347 "Transform.puma"
  544.   {
  545. # line 348 "Transform.puma"
  546.    MakeFuncParams (t->BTE_LIST.Next);
  547. # line 349 "Transform.puma"
  548.    MakeFuncParams (t->BTE_LIST.Next);
  549. # line 350 "Transform.puma"
  550.  t->Kind = kBTP_LIST;
  551.        t->BTP_LIST.Elem = mVAR_PARAM (mADDR(t->BTE_LIST.Elem));
  552.   }
  553.    return;
  554.  
  555.   }
  556.   if (t->Kind == kBTE_EMPTY) {
  557. # line 354 "Transform.puma"
  558.   {
  559. # line 355 "Transform.puma"
  560.  t->Kind = kBTP_EMPTY;
  561.   }
  562.    return;
  563.  
  564.   }
  565. ;
  566. }
  567.  
  568. tTree ExpToVarParam
  569. # if defined __STDC__ | defined __cplusplus
  570. (register tTree exp)
  571. # else
  572. (exp)
  573.  register tTree exp;
  574. # endif
  575. {
  576.   if (exp->Kind == kVAR_EXP) {
  577. # line 366 "Transform.puma"
  578.    return (mVAR_PARAM (exp->VAR_EXP.V));
  579.  
  580.   }
  581. # line 370 "Transform.puma"
  582.    return (mVAR_PARAM (mADDR (exp)));
  583.  
  584. }
  585.  
  586. tTree AppendParam
  587. # if defined __STDC__ | defined __cplusplus
  588. (register tTree plist, register tTree param)
  589. # else
  590. (plist, param)
  591.  register tTree plist;
  592.  register tTree param;
  593. # endif
  594. {
  595.   if (plist->Kind == kBTP_EMPTY) {
  596. # line 376 "Transform.puma"
  597.    return mBTP_LIST (param, plist);
  598.  
  599.   }
  600.   if (plist->Kind == kBTP_LIST) {
  601. # line 380 "Transform.puma"
  602.   {
  603. # line 381 "Transform.puma"
  604.  plist->BTP_LIST.Next = AppendParam (plist->BTP_LIST.Next, param);
  605.   }
  606.    return plist;
  607.  
  608.   }
  609.  yyAbort ("AppendParam");
  610. }
  611.  
  612. void BeginTransform ()
  613. {
  614. }
  615.  
  616. void CloseTransform ()
  617. {
  618. }
  619.